﻿using System;
using System.Collections.Generic;

namespace LocalOverride.Fiddler.Store
{
    class UrlValidUriValidator : IValidator
    {
        private readonly MappingEntry mappingEntry;

        public UrlValidUriValidator(MappingEntry mappingEntry)
        {
            this.mappingEntry = mappingEntry;
        }

        public ValidationResult Validate()
        {
            var error = new ErrorNotification("Url", "Invalid Url");
            try
            {
                if (String.IsNullOrEmpty(mappingEntry.Url))
                {
                    return new ValidationResult(false, error);
                }
                else
                {
                    new Uri(mappingEntry.Url);
                    return ValidationResult.Valid;
                }
            }
            catch (UriFormatException)
            {
                return new ValidationResult(false, error);
            }
        }

    }
}